//
//  CustomSecondViewController.m
//  AmountBody
//
//  Created by smm on 2018/1/2.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CustomSecondViewController.h"
#import "CustomSecondCollectionViewCell.h"
#import "CustomSecondTwoCollectionViewCell.h"
#import "CustomSecondCollectionReusableView.h"
#import "SearchView.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import "HJShapedImageView.h"
#import "CellHeadeView.h"
#import "PopUpButton.h"
#import "CustomContainerView.h"
static const CGFloat JianGe = 5;
static const CGFloat buttonViewTag = 2000000;

static const CGFloat itemWidth = 65;
#define itemHeight itemWidth+40
@interface CustomSecondViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UIScrollViewDelegate>

@property (nonatomic, strong) ABNavigationBar *navigationBar;

//面料选择按钮
@property (strong, nonatomic)  UIButton *fabricButton;
- (void)fabricButton:(UIButton *)sender;
@property (strong, nonatomic)  UIButton *styleButton;
- (void)styleButton:(UIButton *)sender;
@property (strong, nonatomic)  UIImageView *backGroundImage;
@property (strong, nonatomic)  UIView *backGroundView;
@property (strong, nonatomic)  UIView *buttonView;


@property (strong, nonatomic)  UIView *b_lineView;
@property (strong, nonatomic)  UIView *rulerView;

@property (strong, nonatomic)  UIButton *amountButton;
@property (strong, nonatomic)  UIImageView *amountImage;

- (void)amountButton:(UIButton *)sender;

@property (strong, nonatomic)  UICollectionView *collectionView;
@property (strong, nonatomic)  UICollectionView *collectionTwoView;//选中数据展示View

@property (strong, nonatomic) SearchView *searchView;
@property (strong, nonatomic) UILabel * typeNameLabel;
@property (strong, nonatomic) UIImageView * jiandaoLine;//竖屏时的剪刀线

@property (strong, nonatomic) NSMutableArray * dataArray;
@property (strong, nonatomic) NSMutableArray * contentArray;
@property (assign, nonatomic) int needTag;//头部切换按钮
@property (assign, nonatomic) BOOL isMTM;//是否是MTM面料
@property (strong, nonatomic) HJShapedImageView *tagView;
@property (strong, nonatomic) CustomSecondCollectionViewCell * cell;
@property (strong, nonatomic) CellHeadeView * cellView;//collectionView头部悬停
@property (strong, nonatomic) CellHeadeView * cellNameView;//collectionView头部悬停

@end

@implementation CustomSecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.canScrollToNext = YES;
    if (!_isDepth) {
        self.target = CustomSubviewControllerTypeDepthDesign;
    }else{
        self.target = CustomSubviewControllerTypeMeasure;
    }
//    self.view.backgroundColor = RGBColorAlpha(234, 234, 234, 1);
    [self loadUI];
    [self dataForTemporaryArray];
    
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    @weakify(self);
    [SearchView blockForTextField:^(NSString *text) {
        @strongify(self);
        if (self) {
            //搜索
            NSLog(@"搜索******   *********");
        }
       
    }];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}

#pragma mark - 懒加载

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray array]init];
    }
    return _dataArray;
}
- (NSMutableArray *)contentArray
{
    if (!_contentArray) {
        _contentArray = [[NSMutableArray array]init];
    }
    return _contentArray;
}

-(void)dataForTemporaryArray
{
    [self.dataArray removeAllObjects];
    [self.contentArray removeAllObjects];
    if (_isDepth) {
        CustomSecondModel * model = [[CustomSecondModel alloc]init];
        model.name = @"刺绣部位";
        model.childArray = [NSMutableArray array];
        model.item_H = 100;
        model.item_W = 200;
        model.cellType = CellTypeForEmbroid;//刺绣
        model.canMoreChoose = YES;
        for (int i=0; i<10; i++) {
            CustomSecondModel * l_model = [[CustomSecondModel alloc]init];
            
            l_model.name = @"右里袋上方的面料上（直过面除外）";
            l_model.imageUrl = @"cixiu_weixuan";//cixiu_xuan
            l_model.cellType = CellTypeForEmbroid;
            [model.childArray addObject:l_model];
        }
        [self.dataArray addObject:model];
    }else{
        for (int i=0 ; i<4; i++) {
            CustomSecondModel * model = [[CustomSecondModel alloc]init];
            model.name = @"撞色部位";
            model.childArray = [NSMutableArray array];
            model.item_H = itemHeight;
            model.cellType = CellTypeForNomal;
            if (_needTag == 0) {
                
            }else{
                if(_needTag == 2 && i == 0){
                    model.item_H = 60;
                    model.cellType = CellTypeForName;
                    
                }else if (_needTag == 1 &&  i == 0){
                    model.canMoreChoose = YES;
                }
                model.isMore = YES;
            }
            
            for (int j=0; j<10; j++) {
                CustomSecondModel * l_model = [[CustomSecondModel alloc]init];
                l_model.name = @"单排一粒扣";
                l_model.imageUrl = @"xuanzekuang";
                if (!model.isMore) {
                    l_model.cellType = model.cellType;
                    l_model.isPay = YES;
                    if (j ==0 ) {
                        l_model.isChoose = YES;
                        
                    }else if (j==1){
                        l_model.cellType = CellTypeForText;
                    }
                }else{
                    if (j == 0) {
                        l_model.cellType = CellTypeForLabel;
                        
                    }else if (j ==1 ) {
                        l_model.isChoose = YES;
                        l_model.cellType = model.cellType;
                    }else{
                        l_model.cellType = model.cellType;
                    }
                }
                [model.childArray addObject:l_model];
            }
            
            [self.dataArray addObject:model];
            
        }
    }
    
    for (int i=0 ; i<12; i++) {
        CustomSecondModel * model = [[CustomSecondModel alloc]init];
        model.name = @"西装-单排一粒扣 西装-单排一粒扣";
        if (i ==0 ) {
            model.isChoose = YES;
        }
        
        [self.contentArray addObject:model];
    }
    [_collectionView reloadData];
    [_collectionTwoView reloadData];
}

#pragma mark - 竖屏适配
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self loadUILayout];
}
#pragma mark - UI布局
-(void)loadTagView
{
    CGRect cellInCollection = [_collectionView convertRect:_cell.frame toView:_collectionView.superview];
    PopUpButton *button = [[PopUpButton alloc] init];
    button.title = @"半手工材料需收费";
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = More_Little_Font;
    [button.titleLabel sizeToFit];
    [button sizeToFit];
    button.frame = CGRectMake(0, 0, button.frame.size.width+20, button.frame.size.height);
    if (cellInCollection.origin.x <= _collectionView.frame.size.width/2.0) {
        cellInCollection = CGRectMake(cellInCollection.origin.x+10, cellInCollection.origin.y, button.frame.size.width, 25);
        UIImage *image = [UIImage imageNamed:@"left_pay"];
        image = [image stretchImageWithInsetsTop:0 left:7 bottom:0 right:26];
        button.image = image;
    }else{
        cellInCollection = CGRectMake(cellInCollection.origin.x-(button.frame.size.width+20)+cellInCollection.size.width-10, cellInCollection.origin.y, button.frame.size.width+20, 25);
        UIImage *image = [UIImage imageNamed:@"right_pay"];
        image = [image stretchImageWithInsetsTop:0 left:26 bottom:0 right:7];
        button.image = image;
    }
    [button showFromRect:cellInCollection inView:_collectionView.superview];
}

-(void)loadUI
{
    CGFloat jianGeH = 20;
    CGFloat jianGeW = 20;
    CGFloat top = 100; // 顶端盖高度
    CGFloat bottom = 20 ; // 底端盖高度
    CGFloat left = 80; // 左端盖宽度
    CGFloat right = 20; // 右端盖宽度
    
    _backGroundImage = [[UIImageView alloc]init];
    [self.rightView addSubview:_backGroundImage];
    _backGroundImage.userInteractionEnabled = YES;
    
    UIImage * image = [UIImage imageNamed:@"c_kuanshi"];
    if (_isDepth) {
        image = [UIImage imageNamed:@"shendushejibeijing"];
        _collectionTwoView.hidden = YES;
    }else{
        _collectionTwoView.hidden = NO;
    }
    image = [image stretchImageWithInsetsTop:top left:left bottom:bottom right:right];
    _backGroundImage.image = image;
    
//    self.rightContainerView.backgroundImage = image;
    _backGroundView = [[UIView alloc]init];
    _backGroundView.backgroundColor = [UIColor clearColor];
    _backGroundImage.layer.masksToBounds = YES;
    [_backGroundImage addSubview:_backGroundView];
    CGFloat buttonW = 60;
    CGFloat buttonH = buttonW;
    _fabricButton = [[UIButton alloc]init];
    [_backGroundImage addSubview:_fabricButton];
   
    [_fabricButton addTarget:self action:@selector(fabricButton:) forControlEvents:UIControlEventTouchUpInside];
    [_fabricButton setTitle:@"面料\n选择" forState:UIControlStateNormal];
    _fabricButton.titleLabel.font = Cell_Medium_Font;
    _fabricButton.lineBreakMode = NSLineBreakByWordWrapping;
    [_fabricButton setYuanJiaoForRadius:8.0 andMasks:NO];
    [_fabricButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _fabricButton.backgroundColor = ZhuBack_color;
    
    _styleButton = [[UIButton alloc]init];
    [_backGroundImage addSubview:_styleButton];
    _styleButton.hidden = YES;
    [_styleButton addTarget:self action:@selector(styleButton:) forControlEvents:UIControlEventTouchUpInside];
    
    _styleButton.titleLabel.font = Cell_Medium_Font;
    _styleButton.lineBreakMode = NSLineBreakByWordWrapping;
    [_styleButton setTitle:@"款式\n选择" forState:UIControlStateNormal];
    [_styleButton setYuanJiaoForRadius:8.0 andMasks:NO];
    [_styleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _styleButton.backgroundColor = ZhuBack_color;

    _buttonView = [[UIView alloc]init];
    [_backGroundView addSubview:_buttonView];
    _buttonView.frame = CGRectMake(0, 0, 150, 30);
    [self loadButtonViewForUI];
    _searchView = [[SearchView alloc]init];//WithFrame:CGRectMake(0, 0, _backGroundView.frame.size.width, buttonViewH)
    [_backGroundView addSubview:_searchView];
    _typeNameLabel = [[UILabel alloc]init];
    [_backGroundView addSubview:_typeNameLabel];
    _typeNameLabel.text = @"面料分类";
    _typeNameLabel.textColor = ZhongZi_Color;
    _typeNameLabel.font = [UIFont systemFontOfSize:18.0];
    [_typeNameLabel sizeToFit];
    
    _rulerView = [[UIView alloc]init];
    [_backGroundView addSubview:_rulerView];
    
    _jiandaoLine = [[UIImageView alloc]init];
    _jiandaoLine.contentMode = UIViewContentModeScaleAspectFit;
    [_backGroundView addSubview:_jiandaoLine];
    _jiandaoLine.image = [UIImage imageNamed:@"jiandaoLine"];
    _jiandaoLine.hidden = YES;
    _cellView = [[CellHeadeView alloc]init];
    [_backGroundView addSubview:_cellView];
    _cellView.cellType = CellHeadTypeForNomal;
    [_cellView setCellHeadWithName:@"前门扣"];
    _cellView.backgroundColor = TAB_BAR_COLOR;
    
    _cellNameView = [[CellHeadeView alloc]init];
    _cellNameView.backgroundColor = TAB_BAR_COLOR;
    [_backGroundView addSubview:_cellNameView];
    _cellNameView.cellType = CellHeadTypeForLittleTitle;
    [_cellNameView setCellHeadWithName:@"刺绣部位"];
    
    
    UICollectionViewFlowLayout  *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 150) collectionViewLayout:layout];
    [_backGroundView addSubview:_collectionView];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.showsVerticalScrollIndicator = NO;
    [_collectionView registerClass:[CustomSecondCollectionViewCell class] forCellWithReuseIdentifier:@"CustomSecondCollectionViewCell"];
    [_collectionView registerClass:[CustomSecondCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CustomSecondCollectionReusableView"];
//    _collectionView.sectionHeadersPinToVisibleBounds = YES;
    _collectionView.backgroundColor = TAB_BAR_COLOR;
//    [_collectionView setYuanJiaoForRadius:10.0 andMasks:NO];
    _tagView = [[HJShapedImageView alloc]init];
    [_backGroundView addSubview:_tagView];
    
    _tagView.hidden = YES;
    UICollectionViewFlowLayout  *layout2 = [[UICollectionViewFlowLayout alloc] init];
    layout2.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout2.minimumLineSpacing = JianGe;
    layout2.minimumInteritemSpacing = JianGe;
    _collectionTwoView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 150) collectionViewLayout:layout2];
    [_collectionTwoView setYuanJiaoForRadius:10.0 andMasks:NO];
    [_backGroundView addSubview:_collectionTwoView];
    _collectionTwoView.backgroundColor = TAB_BAR_COLOR;
    _collectionTwoView.delegate = self;
    _collectionTwoView.dataSource = self;
    
    _collectionTwoView.showsHorizontalScrollIndicator = NO;
    _collectionTwoView.showsVerticalScrollIndicator = NO;
    [_collectionTwoView registerClass:[CustomSecondTwoCollectionViewCell class] forCellWithReuseIdentifier:@"CustomSecondTwoCollectionViewCell"];
    _amountButton = [[UIButton alloc]init];
    [_amountButton addTarget:self action:@selector(amountButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_amountButton];
    [self.view bringSubviewToFront:_amountButton];
    _amountImage = [[UIImageView alloc]init];
    [_amountButton addSubview:_amountImage];
    if (_isDepth) {
        _fabricButton.hidden = YES;
        _searchView.hidden = NO;
        _buttonView.hidden = YES;
    }else{
        _fabricButton.hidden = NO;
        _searchView.hidden = YES;
        _buttonView.hidden = NO;
        
    }
}
-(void)buildAmountButton
{
    CGFloat buttonW = 60;
    CGFloat buttonH = buttonW;
    CGFloat l_imageH = 12;
    [_amountButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _amountButton.backgroundColor = ZhuBack_color;
    NSString * str = @"直接进入\n";
    NSString * str2 = @"量体";
    NSString * str3 = @"\n";
    NSString * needStr = [NSString stringWithFormat:@"%@%@%@",str,str2,str3];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:10.0f]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:[UIColor whiteColor]
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:RGBColorAlpha(227, 65, 85, 1)
                    range:NSMakeRange(str.length, str2.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:15.0f]
                    range:NSMakeRange(str.length, str2.length)];
    _amountButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_amountButton setAttributedTitle:attrStr forState:UIControlStateNormal];
    [_amountButton setYuanJiaoForRadius:buttonH/2.0 andMasks:NO];
    _amountButton.lineBreakMode = NSLineBreakByWordWrapping;
    _amountImage.image = [UIImage imageNamed:@"@down"];
    _amountImage.userInteractionEnabled = YES;
//    CALayer *layer2 = [CALayer layer];
//    layer2.frame = CGRectMake(SCREEN_W-buttonW-20-10, SCREEN_H-TOPNAVIGATIONBAR_H-USERDEFINED_TABBAR_H-20-buttonH, buttonW, buttonH);
//    layer2.backgroundColor = [UIColor whiteColor].CGColor;
//    layer2.shadowOffset = CGSizeMake(0, 0);
//    layer2.shadowColor = RGBColor(205, 205, 205).CGColor;
//    layer2.shadowOpacity = 0.4;
//    layer2.cornerRadius = buttonH/2.0;
    if (_isDepth) {
        _amountButton.hidden = YES;
    }else{
        _amountButton.hidden = NO;
        
    }
    [_amountButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-(20));
        make.right.equalTo(self.view).offset(-(30));
        make.width.height.equalTo(@(buttonH));
    }];
    [_amountImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@(l_imageH));
        make.left.equalTo(@((buttonH-l_imageH)/2.0));
        make.top.equalTo(@((buttonH-l_imageH)/2.0+15));
    }];
}

-(void)buildAmountButtonForVertical
{
    CGFloat buttonW = 160;
    CGFloat buttonH = 30;
    CGFloat l_imageH = 12;
    [_amountButton setTitleColor:ZhongZi_Color forState:UIControlStateNormal];
    _amountButton.backgroundColor = [UIColor clearColor];
    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"直接进入量体"];
    _amountButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    _amountButton.titleLabel.font = Cell_Medium_Font;
    [_amountButton setAttributedTitle:attrStr forState:UIControlStateNormal];
    [_amountButton setYuanJiaoForRadius:buttonH/2.0 andMasks:NO];
    _amountButton.lineBreakMode = NSLineBreakByWordWrapping;
    
    _amountImage.image = [UIImage imageNamed:@"infolist_header_right"];
    _amountImage.userInteractionEnabled = YES;
    if (_isDepth) {
        _amountButton.hidden = YES;
    }else{
        _amountButton.hidden = NO;
        
    }
    [_amountButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-(30));
        make.height.equalTo(@(buttonH));
        make.width.equalTo(@(buttonW));
    }];
    [_amountImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@(l_imageH));
        make.right.equalTo(_amountButton);
        make.top.equalTo(@((buttonH-l_imageH)/2.0));
    }];
}
-(void)loadUILayout
{
    
    CGFloat buttonW = 60;
    CGFloat buttonH = buttonW;
    CGFloat buttonViewW = 3*50;
    CGFloat buttonViewH = 30;
    CGFloat multiplie = 0.68;
    CGFloat top = 100; // 顶端盖高度
    CGFloat bottom = 20 ; // 底端盖高度
    CGFloat left = 80; // 左端盖宽度
    CGFloat right = 20; // 右端盖宽度
    //_amountButton
    layoutViews(^{
        [self buildAmountButton];
    }, ^{
        [self buildAmountButtonForVertical];
    });
    [_backGroundImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.rightView);
        if (_isDepth) {
            make.bottom.equalTo(self.rightView).offset(-20);
        }else{
            make.bottom.equalTo(self.rightView).offset(-20);
        }
        
        layoutViews(^{
            make.left.equalTo(self.rightView);
        }, ^{
            make.left.equalTo(self.rightView).offset(20);
            make.right.equalTo(self.rightView).offset(-20);
        });
    }];
    [_backGroundView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_backGroundImage).insets(UIEdgeInsetsMake(top-40, 50, bottom, right));
    }];
    [_fabricButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_backGroundView);
        make.width.height.equalTo(@(buttonH));
        make.top.equalTo(@15);
    }];
    [_styleButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_fabricButton.mas_left).offset(-10);
        make.width.height.equalTo(@(buttonH));
        make.top.equalTo(@15);
    }];
    [_buttonView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.right.equalTo(_backGroundView);
            make.top.equalTo(_backGroundView).offset(30);
            make.width.equalTo(@(buttonViewW));
            make.height.equalTo(@(buttonViewH));
        }, ^{ //竖屏
            make.centerX.equalTo(_backGroundView).offset(-20);
            make.top.equalTo(_backGroundView);
            make.width.equalTo(@(buttonViewW));
            make.height.equalTo(@(buttonViewH));
        });
    }];
    
    [_typeNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            _typeNameLabel.hidden = YES;
            
        }, ^{ //竖屏
            _typeNameLabel.hidden = NO;
            
        });
        make.top.equalTo(_backGroundView).offset(40);
        make.height.equalTo(@40);
        make.left.equalTo(_backGroundView);
    }];
    [_jiandaoLine mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{
            _jiandaoLine.hidden = YES;
        }, ^{
            _jiandaoLine.hidden = NO;
        });
        make.left.equalTo(_backGroundView);
        make.width.equalTo(@18);
        make.top.equalTo(_typeNameLabel.mas_bottom);
        make.bottom.equalTo(_backGroundView).offset(-32);
    }];
    [_searchView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.left.equalTo(_typeNameLabel.mas_right).offset(10);
            make.right.equalTo(_backGroundView);
            make.top.equalTo(_backGroundView).offset(30);
            make.height.equalTo(@(buttonViewH));
        }, ^{ //竖屏
            
            make.top.equalTo(_backGroundView);
            make.width.equalTo(_backGroundView).multipliedBy(0.5);
            make.centerX.equalTo(_backGroundView).offset(-60);
            make.height.equalTo(@(buttonViewH));
        });
    }];
    [_rulerView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.left.right.equalTo(_backGroundView);
            make.top.equalTo(_buttonView.mas_bottom);
            make.height.equalTo(@80);
        }, ^{ //竖屏
            make.right.equalTo(_backGroundView);
            make.top.equalTo(_backGroundView).offset(30);
            make.width.equalTo(_backGroundView).multipliedBy(multiplie);
            make.height.equalTo(@80);
        });
    }];
    [_cellView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            _cellView.cellType = CellHeadTypeForNomal;
            [_cellView setCellHeadWithName:@"前门扣"];
            make.left.right.equalTo(_backGroundView);
            make.top.equalTo(_rulerView.mas_bottom);
            make.height.equalTo(@65);
            _cellView.backgroundColor = TAB_BAR_COLOR;
        }, ^{ //竖屏
            _cellView.cellType = CellHeadTypeForVertical;
            [_cellView setCellHeadWithName:@"前门扣"];
            make.left.equalTo(_backGroundView);
            make.bottom.equalTo(_backGroundView).offset(-10);
            make.width.equalTo(_backGroundView).multipliedBy(0.29);
            make.height.equalTo(@45);
            _cellView.backgroundColor = [UIColor clearColor];
        });
    }];
   
    if (_isDepth) {

        _cellNameView.hidden = NO;
        [_cellNameView mas_remakeConstraints:^(MASConstraintMaker *make) {
            layoutViews(^{ //横屏
                make.left.right.equalTo(_backGroundView);
                make.top.equalTo(_cellView.mas_bottom);
                make.height.equalTo(@20);
            }, ^{ //竖屏
                make.right.equalTo(_backGroundView);
                make.top.equalTo(_rulerView.mas_bottom);
                make.width.equalTo(_backGroundView).multipliedBy(multiplie);
                make.height.equalTo(@30);
            });
        }];
    }else{
        _cellNameView.hidden = YES;
        [_cellNameView mas_remakeConstraints:^(MASConstraintMaker *make) {
            layoutViews(^{ //横屏
                make.left.right.equalTo(_backGroundView);
                make.top.equalTo(_cellView.mas_bottom);
                make.height.equalTo(@0);
            }, ^{ //竖屏
                make.right.equalTo(_backGroundView);
                make.top.equalTo(_rulerView.mas_bottom);
                make.width.equalTo(_backGroundView).multipliedBy(multiplie);
                make.height.equalTo(@0);
            });
        }];
    }
    [_collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.left.right.equalTo(_backGroundView);
            make.top.equalTo(_cellNameView.mas_bottom);
            make.height.equalTo(@170);
        }, ^{ //竖屏
            make.right.equalTo(_backGroundView);
            make.width.equalTo(_backGroundView).multipliedBy(multiplie);
            make.top.equalTo(_cellNameView.mas_bottom);
            make.height.equalTo(@190);
        });
    }];
    [_collectionTwoView mas_remakeConstraints:^(MASConstraintMaker *make) {
        layoutViews(^{ //横屏
            make.left.right.equalTo(_backGroundView);
            make.top.equalTo(_collectionView.mas_bottom).offset(10);
            make.bottom.equalTo(_backGroundView).offset(-20);;
            _collectionTwoView.backgroundColor = TAB_BAR_COLOR;
        }, ^{ //竖屏
            make.left.equalTo(_jiandaoLine.mas_right).offset(5);
            make.width.equalTo(_backGroundView).multipliedBy(0.29).offset(-5);
            make.top.equalTo(_typeNameLabel.mas_bottom).offset(20);
            make.bottom.equalTo(_cellView.mas_top);
            _collectionTwoView.backgroundColor = [UIColor whiteColor];
        });
    }];
    if (_isDepth) {
        [_collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_backGroundView).offset(-20);
        }];
        [_collectionTwoView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@0);
        }];
        [_collectionView reloadData];
    }
    
}

-(void)loadButtonViewForUI
{
    for (UIView * view in _buttonView.subviews) {
        [view removeFromSuperview];
    }
    [_backGroundView layoutIfNeeded];
    CGFloat jianGe = 20;
    CGFloat buttonW = (_buttonView.frame.size.width-20*2)/3.0;
    CGFloat buttonH = 30;
    CGFloat lineW = 40;
    CGFloat lineH = 2;
    NSArray * nameArr = @[@"正装",@"休闲",@"礼服"];
    for (int i=0; i<3; i++) {
        UIButton * button = [[UIButton alloc]init];
        [_buttonView addSubview:button];
        [button mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_buttonView);
            make.width.equalTo(@(buttonW));
            make.height.equalTo(@( buttonH-lineH));
            make.left.equalTo(@((buttonW+jianGe)*i));
        }];
        [button addTarget:self action:@selector(buttonFunc:) forControlEvents:UIControlEventTouchUpInside];
        button.titleLabel.font  = Cell_Big_Font;
        button.tag = buttonViewTag+i;
        [button setTitle:nameArr[i] forState:UIControlStateNormal];
        [button setTitleColor:ShenZi_Color forState:UIControlStateNormal];
        
    }
    
    UIButton * tmpButton = [_buttonView viewWithTag:buttonViewTag];
    [tmpButton setTitleColor:RGBColorAlpha(255, 66, 89, 1) forState:UIControlStateNormal];
    _b_lineView = [[UIView alloc]init];
//    _b_lineView.frame = CGRectMake(tmpButton.frame.origin.x+(buttonW-lineW)/2.0, buttonH-lineH, lineW, lineH);
    [_buttonView addSubview:_b_lineView];
    [_b_lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(tmpButton);
        make.top.equalTo(tmpButton.mas_bottom);
        make.height.equalTo(@(lineH));
        
    }];
    _b_lineView.backgroundColor = RGBColorAlpha(255, 66, 89, 1);
    
}
- (UILabel*)titleLabel
{
    CGRect labelFrame = CGRectMake(0, 0, 30, 44);
    UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
    NSString * name = GDLocalizedString(@"design");
    label.text = name;
    label.font = [UIFont systemFontOfSize:18];
    label.textColor = [UIColor whiteColor];
    [label sizeToFit];
    label.frame = CGRectMake((SCREEN_W-label.frame.size.width)/2.0, 20, label.frame.size.width, 44);
    return label;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    self.canScrollToNext = YES;
}


#pragma mark --- UICollectionViewDelegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if (collectionView == _collectionTwoView) {
        return 1;
    }else{
        return self.dataArray.count;
    }
    
}
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    CustomSecondCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CustomSecondCollectionReusableView" forIndexPath:indexPath];
    [headerView setCellHeadWithLine];

    return headerView;
}
-(CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    if (collectionView == _collectionTwoView) {
        return CGSizeZero;
    }else if (section >0){
        CGSize size = {SCREEN_W, 10};
        return size;
    }else{
        return CGSizeZero;
    }
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CustomSecondModel * tmpModel = [_dataArray objectAtIndex:indexPath.section];
    
    if (collectionView == _collectionTwoView) {
        return CGSizeMake(200, 40);
    }else{
        if (tmpModel.cellType == CellTypeForName) {
            return CGSizeMake(itemWidth, tmpModel.item_H);
        }else if (tmpModel.cellType == CellTypeForEmbroid) {
            return CGSizeMake(tmpModel.item_W, tmpModel.item_H);
        }else{
            return CGSizeMake(itemWidth, itemHeight);
        }
        
    }
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == _collectionTwoView) {
        return self.contentArray.count;
    }else{
        CustomSecondModel * tmpModel = [_dataArray objectAtIndex:section];
        return tmpModel.childArray.count;
    }
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    // 需要配置的代码
    if (collectionView == _collectionTwoView) {
        CustomSecondTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomSecondTwoCollectionViewCell" forIndexPath:indexPath];
        CustomSecondModel * tmpModel = [_contentArray objectAtIndex:indexPath.row];
        tmpModel.index = indexPath;
        cell.cell_width = 200;
        [cell setCellWithModel:tmpModel];
        return cell;
    }else{
        CustomSecondCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CustomSecondCollectionViewCell" forIndexPath:indexPath];
        CustomSecondModel * tmpModel = [_dataArray objectAtIndex:indexPath.section];
        CustomSecondModel* model = [tmpModel.childArray objectAtIndex:indexPath.row];
        model.index = indexPath;
        if (_isDepth) {
            cell.item_Width = tmpModel.item_W;
        }else{
            cell.item_Width = itemWidth;
        }
        
        cell.item_Height = tmpModel.item_H;
        cell.backgroundColor = RGBColorAlpha(245, 245, 245, 0.9);
        RAC(cell,cellChoose) = [RACObserve(model, isChoose) takeUntil:[cell rac_prepareForReuseSignal]];
//        RAC(self,tagView) = [RACObserve(model, isChoose) takeUntil:[cell rac_prepareForReuseSignal]];
        [cell setCellWithModel:model andType:model.cellType];
        cell.backgroundColor = [UIColor clearColor];
        return cell;
    }
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    _cell = (CustomSecondCollectionViewCell*)[_collectionView cellForItemAtIndexPath:indexPath];
    if (collectionView == _collectionView) {
        CustomSecondModel * model = [_dataArray objectAtIndex:indexPath.section];
        [model.childArray enumerateObjectsUsingBlock:^(CustomSecondModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (!model.canMoreChoose && obj.isChoose) {
                obj.isChoose = NO;
            }
            
        }];
        
        CustomSecondModel * l_model = [model.childArray objectAtIndex:indexPath.row];
        l_model.valueWords = @"精忠报国";
        l_model.valueFont = @"宋体";
        l_model.valueColor = @"红色";
        l_model.isChoose = !l_model.isChoose;
        if (l_model.isPay) {
            [self loadTagView];
        }
    }
    
}

#pragma mark -  手势方法按钮

-(void)buttonFunc:(UIButton *)button
{
    _needTag = (int)button.tag-buttonViewTag;
    [self dataForTemporaryArray];
    for (int i=0; i<3; i++) {
        UIButton * tmpButton = [_buttonView viewWithTag:buttonViewTag+i];
        [tmpButton setTitleColor:ZhongZi_Color forState:UIControlStateNormal];
    }
    [button setTitleColor:RGBColorAlpha(255, 66, 89, 1) forState:UIControlStateNormal];
    CGFloat lineW = 40;
    CGFloat lineH = 2;
    [_b_lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(button);
        make.top.equalTo(button.mas_bottom);
        make.height.equalTo(@(lineH));
        
    }];
//    _b_lineView.frame = CGRectMake(button.frame.origin.x+(button.frame.size.width-lineW)/2.0, button.frame.size.height-lineH, lineW, lineH);
}

- (void)fabricButton:(UIButton *)sender {
    
    CGFloat top = 100; // 顶端盖高度
    CGFloat bottom = 20 ; // 底端盖高度
    CGFloat left = 80; // 左端盖宽度
    CGFloat right = 20; // 右端盖宽度
    _isMTM = !_isMTM;
    UIImage * image = [UIImage imageNamed:@"mianliao xuanze"];
    // 指定为拉伸模式，伸缩后重新赋值
    image = [image stretchImageWithInsetsTop:top left:left bottom:bottom right:right];
    _backGroundImage.image = image;
    if (_isMTM) {
        [_fabricButton setTitle:@"MTM\n面料" forState:UIControlStateNormal];
    }else{
        [_fabricButton setTitle:@"客供\n面料" forState:UIControlStateNormal];
    }
    _fabricButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_fabricButton setTitleColor:RGBColorAlpha(255, 66, 89, 1) forState:UIControlStateNormal];
    _styleButton.hidden = NO;
    _buttonView.hidden = YES;
    _searchView.hidden = NO;
    if (_isDepth) {
        _typeNameLabel.hidden = YES;
    }else{
        _typeNameLabel.hidden = NO;
    }
}
- (void)amountButton:(UIButton *)sender {
    NSLog(@"点击量体按钮");
}
- (void)styleButton:(UIButton *)sender {
    _styleButton.hidden = YES;
    _buttonView.hidden = NO;
    _searchView.hidden = YES;
    _typeNameLabel.hidden = YES;
    _isMTM = NO;
    CGFloat top = 100; // 顶端盖高度
    CGFloat bottom = 20 ; // 底端盖高度
    CGFloat left = 80; // 左端盖宽度
    CGFloat right = 20; // 右端盖宽度
    UIImage * image = [UIImage imageNamed:@"c_kuanshi"];
    // 指定为拉伸模式，伸缩后重新赋值
    image = [image stretchImageWithInsetsTop:top left:left bottom:bottom right:right];
    _backGroundImage.image = image;
    [_fabricButton setTitle:@"面料\n选择" forState:UIControlStateNormal];
    [_fabricButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
@end
